#include <iostream>
#include <stack>
#include <string>
using namespace std;

int main()
{
    stack<int> st;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        string s;
        cin >> s;
        if (s.compare("push") == 0)
        {
            int x;
            cin >> x;
            st.push(x);
        }
        if (s.compare("pop") == 0)
        {
            if (!st.empty()) st.pop();
            else cout << "Empty" << endl;
        }
        if (s.compare("query") == 0)
        {
            if (!st.empty()) cout << st.top() << endl;
            else cout << "Empty" << endl;
        }
        if (s.compare("size") == 0)
        {
            cout << st.size() << endl;
        }
    }
    return 0;
}